package com.yidu.user.controller;

import com.yidu.user.entity.PerUser;
import com.yidu.user.service.PerUserService;
import com.yidu.user.utils.YmlConfig;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 用户表(PerUser)表控制层
 *
 * @author liandyao
 * @since 2020-07-21 08:46:53
 */
@Api("用户的接口信息,提供了增删改查方法")
@RestController
public class PerUserController {

    public Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     * 服务对象
     */
    @Resource
    private PerUserService perUserService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation(value="根据ID查询",notes = "传入一个整数类型的ID,得到json结果")
    @GetMapping("user/{id}")
    public PerUser selectOne(@PathVariable("id") Integer id) {
        logger.info("user这边传过来的ID:"+id);
        return this.perUserService.queryById(id);
    }


    @Resource
    YmlConfig ymlConfig;

    @GetMapping("config")
    public Map<String,String> getYmlConfig(){
        logger.info("进来读取配置文件");
        Map<String,String> map = new HashMap<>();
        map.put("name",ymlConfig.getName());
        map.put("instance",ymlConfig.getInstanceId());

        return map ;
    }

}